package com.inspur.gs.sbssdl.sbyxgl.djjh.djjh.back.sbdjpz.validations;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.bef.engine.entity.AssociationInfo;
import com.inspur.edp.cef.api.message.*;
import com.inspur.edp.bef.api.action.validation.*;
import com.inspur.edp.bef.spi.action.validation.*;
import com.inspur.edp.cef.entity.changeset.*;
import com.inspur.edp.bef.spi.action.validation.AbstractValidation;
import com.inspur.edp.bef.api.action.validation.IValidationContext;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.cef.entity.entity.IEntityDataCollection;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.List;

public class sbdjpzValBeforeSave1MgrAction extends AbstractValidation {
	public sbdjpzValBeforeSave1MgrAction(IValidationContext context, IChangeDetail change) {
		super(context,change);
	}
	@Override
	public  void execute() {
//		IEntityData data=this.getData();
//		String sbid=(String)((AssociationInfo) data.getValue("sbid")).getValue("sbid");
//		String year = (String) data.getValue("year");
//		Boolean djpz = (Boolean) data.getValue("djpz");
//
//		IEntityDataCollection sbdjpzmx = data.getChilds().get("sbdjpzmx");
//		if (!djpz&&sbdjpzmx.isEmpty()){
//			SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
//			try {
//				ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
//				String djxzid = "ff554cce-1197-469a-88f1-814f2ed0781d";// 设备点检配置明细id
//				IStandardLcp djxzlcp = iLcpFactory.createLcpByBEId(djxzid);
//				List<IEntityData> djxzlist = djxzlcp.query();
//				for (IEntityData item : djxzlist) {
//					String oriyear = (String) item.getValue("year");
//					String orisbid = (String) ((AssociationInfo) item.getValue("sbid")).getValue("sbid");
//					System.out.println(orisbid);
//					System.out.println(oriyear);
//					if (oriyear.equals(year)&&orisbid.equals(sbid)){
//						throw new RuntimeException("该年份的设备已添加，请重新添加！");
//					}
//				}
//			} finally {
//				SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
//			}
//		}
	}
	private IEntityData getData() {
		return (IEntityData)super.getContext().getCurrentData();
	}
}